package homework;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 生成10个0-100的随机数并存入一个List集合中并输出
 * 之后将集合第3到第6个元素翻转并输出
 * 
 * @author Xiloer
 *
 */
public class Test04 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        for (int i=0;i<=100;i++){
            list.add(i+"");
        }

        Random rand = new Random();
        List<String> randomList = new ArrayList<>();
        String random = list.get(rand.nextInt(101));
        int count = 0;
        while(true) {
            if (randomList.contains(random))
                random = list.get(rand.nextInt(101));
            else{
                randomList.add(random);
                count++;
            }
            if (count == 10)
                break;
        }
        System.out.print("[ ");
        for (int i=0;i<randomList.size();i++){
            System.out.print (randomList.get(i)+" ");
        }
        System.out.println("]");

        List<String> subList = randomList.subList(2,6);
        subList = subList.reversed();
        System.out.print("[ ");
        for (int i=0;i<subList.size();i++){
            System.out.print (subList.get(i)+" ");
        }
        System.out.println("]");
    }
}
